﻿using System;
using MeetingAssistant.Domain.Model.Member;
using MeetingAssistant.ViewModel.Member;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;

namespace MeetingAssistant.Domain.Data.Repositories.Member.Impl
{
    public partial class UserRepository
    {
        public IList<UserVM> GetListUserVM(Expression<Func<User, bool>> wh, int limit, int offset, out int total, string name)
        {
            var list = Context.Users.Where(c => c.Company.CompanyName == name.ToString())
                        .Select(user => new UserVM()
                        {
                            Id = user.Id,
                            UserName = user.UserName,
                            TrueName = user.TrueName,
                            Sex = user.Sex,
                            IdentityNumber = user.IdentityNumber,
                            Email = user.Email,
                            Phone = user.Phone,
                            Department = user.Department,
                            CompanyName = user.Company.CompanyName,
                            Address = user.Address,
                            Enabled = user.Enabled,
                            UpdateDate = user.UpdateDate
                        });
            
            total = list.Count();
            if (offset > 0)
            {
                return list.OrderBy(c => c.Id).ThenBy(c => c.UpdateDate).Skip(offset).Take(limit).ToList();
            }
            return list.ToList();
        }
    }
}
